package com.lenovo.nova.util.os.application;

import java.util.List;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.UserHandle;

import com.lenovo.nova.util.collection.Collections;
import com.lenovo.nova.util.debug.ObjectUtil;
import com.lenovo.nova.util.os.PackageActivityManagerUtil;

public class StandardAppManager {

	
	protected Context mContext;

	public StandardAppManager(Context context) {
		mContext = context;
	}
	
	public void getProgressPackage(){
		 int mRetrieveFlags;
		// Only the owner can see all apps.
        if (UserHandle.myUserId() == 0) {
            mRetrieveFlags = PackageManager.GET_UNINSTALLED_PACKAGES |
                    PackageManager.GET_DISABLED_COMPONENTS |
                    PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS;
        } else {
            mRetrieveFlags = PackageManager.GET_DISABLED_COMPONENTS |
                    PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS;
        }
        
        
        List<ApplicationInfo> lists = mContext.getPackageManager().getInstalledApplications(mRetrieveFlags);
        
        Collections.showCollection(lists, new Collections.OnShowCollectionHelper<ApplicationInfo>() {
			@Override
			public void onItem(ApplicationInfo e) {
				ObjectUtil util = new ObjectUtil(":", e.loadLabel(mContext.getPackageManager()) + ":" + e.packageName);
			}

			@Override
			public boolean onCloseInternalPrint() {
				return true;
			}
		});
        
        System.out.println(ObjectUtil.formatPrint());
        
	}
	
	
	/**
	 * 判断系统应用是否有更新了
	 * @param info
	 * @return
	 */
	public boolean isUpdatedSysApp(ApplicationInfo info){
		 boolean mUpdatedSysApp = (info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
		 return mUpdatedSysApp;
	}
	
}
